$(function() {
	var f=true;
	//注册信息验证
	$("input[name='username1'],input[name='password2'],input[name='repassword2']").blur(function(){
		var flag =true;
		var flag2=true;
		var username=$("input[name='username1']").val();
		var password=$("input[name='password2']").val();
		var repassword=$("input[name='repassword2']").val();
		if(username==""){
			flag=flag && false;
		}
		if(password=="")
			flag=flag && false;
			
		if(repassword==""){
			flag=flag && false;
		} 
		f=flag;
		if(repassword!=password){
			flag2=flag2 && false;
		}
		f2=flag2;
		
	});
	
	
	//为注册按钮绑定点击注册时间  出发regist方法
	$("#sub_regist").click(function(){
		if(!f){
			alert("用户名或密码不能为空！")
		}else if(!f2){
			alert("两次密码不一致！")
		}else{ 
			return regist();
		}
	});
})

function regist(){
	var username=$("input[name='username1']").val();
	var password=$("input[name='password2']").val();
	
	$.ajax({
		url:"user/regist",
		data:{userName:username,passWord:password},
		type:"post",
		dataType:"json",
		async:false,
		success:function(data){
			var flag=data.success;
			if(flag){
				alert("恭喜您注册成功！");
				window.location.href="login.html";
			}else{
				var msg = data.message;
				alert(msg);
			}
		},
		error:function(e){
			alert("请求失败！");
		}
	})
}